package com.shujia.four;

import org.junit.Test;

import java.io.*;

public class InputStreamReaderDemo {



    @Test
    public void test2() throws IOException {
        // 使用转换流的默认编码
        InputStreamReader isr = new InputStreamReader(
                new FileInputStream("file\\b.txt"), "GBK");

        OutputStreamWriter osw = new OutputStreamWriter(
                new FileOutputStream("file\\b_copy.txt"), "UTF-16");
//        FileWriter fw = new FileWriter("file\\b_copy.txt");

        char[] chs = new char[60];
        int len;
        while ((len = isr.read(chs)) != -1) {
//            System.out.print(new String(chs, 0, len));
            osw.write(chs, 0, len);
        }

        osw.flush();
        osw.close();
        isr.close();

    }

    @Test
    public void test1() throws IOException {
        // 使用转换流的默认编码
        InputStreamReader isr = new InputStreamReader(
                new FileInputStream("file\\a.txt"));

        FileReader fr = new FileReader("file\\a.txt");

        // isr如果是默认编码, 那么和fr的效果是一样, 一般会选择使用 FileReader

        char[] chs = new char[60];
        int len;
        while ((len = isr.read(chs)) != -1) {
            System.out.print(new String(chs, 0, len));
        }
    }
}
